<?php
/**
 * 银币发放列表
 *
 *
 *
 * * @网店运维 (c) 2015-2018  Inc. (http://www.shopwwi.com)
 * @license    http://www.shopwwi.c om
 * @link       交流群号：111731672
 * @since      网店运维提供技术支持 授权请购买shopnc授权
 */



defined('InShopNC') or exit('Access Invalid!');
class store_silverControl extends BaseSellerControl {
    public function __construct() {
        parent::__construct();
        Language::read ('member_store_goods_index');
    }

    public function indexOp() {
        $model_member = Model('member');
        $condition = array();
        $curpage = empty($_GET['curpage']) ? 1:(int)$_GET['curpage'];
        $condition = array();
        $condition_str = '1';
        if(!empty($_GET['keyword'])) {
            $condition['member_truename|member_mobile'] = array('like', '%'.$_GET['keyword'].'%');
            $condition_str = " AND (member_truename LIKE '%".$_GET['keyword']."%' OR member_mobile LIKE '%".$_GET['keyword']."%')";
        }
        $member_count = $model_member->getMemberCount(array('member_state'=>1));
        Tpl::output('member_count',$member_count);
        $item_count = $model_member->getAffilateTotal();
        Tpl::output('item_count',$item_count);
        $page   = new Page();
        $page->setEachNum(20);
        $page->setStyle('admin');
        $page->setTotalNum($item_count);
        $item_list = $model_member->getAffiliateGradeList($condition_str, 20,$curpage-1);
        Tpl::output('item_list', $item_list);
        $send_count = $model_member->getSliverCount();
        Tpl::output('send_count',$send_count);

        Tpl::output('show_page', $page->show());

        Tpl::showpage('store_silver.list');
    }

    public function addOp(){
        if (chksubmit()){
            $model_member = Model("member");
            $data = array();
            $data['member_id'] = $_POST['member_id'];
            $data['member_name'] = $_POST['member_name'];
            $data['member_truename'] = $_POST['member_truename'];
            $data['member_mobile'] = $_POST['member_mobile'];
            $data['affilite_num'] = $_POST['affilite_num'];
            $data['gift_content'] = $_POST['gift_content'];
            $data['number'] = $_POST['number'];
            $data['gift_time'] = time();
            $result = $model_member->addSilver($data);
            if($result){
                $this->recordSellerLog('用户 '.$_POST['member_name']." ".$_POST['member_mobile'].' 领用银币');
                showDialog('银币发放成功', urlShop('store_silver', 'index'), 'succ');
            }
        }else {
            $member = explode("|",$_GET['member']);
            Tpl::output("member",$member);
            Tpl::showpage('store_silver.add', 'null_layout');
        }
    }

    public function check_member_ajaxOp(){
        $model_member = Model("member");
        $keyword = $_GET['keyword'];
        $member= $model_member->where(array('member_mobile|member_carid'=>$keyword))->find();
        echo json_encode($member);
        exit;
    }

    public function invite_listOp(){
        $model_member = Model("member");
        $invite_count = $model_member->getAffiliateCount($_GET['user_id']);
        $page   = new Page();
        $page->setEachNum(20);
        $page->setTotalNum($invite_count);
        $page->setStyle('admin');
        $invite_list = $model_member->getInviteList(array('user_id'=>$_GET['user_id']),$page);

        Tpl::output('invite_list',$invite_list);
        Tpl::output('show_page',$page->show());
        Tpl::showpage('store_invite_list','null_layout');
    }

    public function silver_listOp(){
        $model_member = Model("member");
        $silver_count = $model_member->getSilverCount(array('member_name'=>$_GET['user_id']));
        $page   = new Page();
        $page->setEachNum(10);
        $page->setTotalNum($silver_count);
        $page->setStyle('admin');
        $silver_list = $model_member->getSilverList(array('member_name'=>$_GET['user_id']),$page);
        Tpl::output('silver_list',$silver_list);
        Tpl::output('show_page',$page->show());
        Tpl::showpage('store_silver_list','null_layout');
    }

}
